from django.db import models
from apps.wx_offical_account.models import WxOfficalAccount
# Create your models here.

from db.base import BaseModel

class ArticleModel(BaseModel):
    pass_chioces = (
        (0,"草稿"),
        (1,"待审核"),
        (2,"发布"),
        (3,"驳回"),
    )
    kyk_ord_id = models.CharField(max_length=64,verbose_name="官网的id",null=True)
    title = models.CharField(max_length=255, verbose_name="文章的标题")
    org_id = models.ForeignKey('wx_offical_account.WxOfficalAccount', verbose_name="关联机构类型的外键")  # 多个文章对应一个 公众号
    # article_type = models.CharField(max_length=32, verbose_name="微信公众号的类型", default="财经")
    # org_name = models.CharField(max_length=32, verbose_name="微信公众号名字", null=False)
    article_author = models.CharField(max_length=32, verbose_name="文章的作者",null=True)
    article_content = models.TextField(verbose_name="文章的内容", null=True)
    crawl_status = models.BooleanField(default=True, verbose_name="文章爬取状态0不可以爬，1可以爬")
    spider_time = models.DateTimeField(verbose_name="爬取时间", auto_now=True)
    article_create_on = models.DateTimeField(verbose_name="抓取的文章创建时间")
    article_update_on = models.DateTimeField(verbose_name="抓取的文章最后更新时间")
    article_link = models.CharField(max_length=255, verbose_name="文章的url ",null=False,default="123456789")
    md5_link = models.CharField(max_length=64,verbose_name="文章url的md5值 唯一索引",null=False,default="123456789",unique=True)
    article_desc = models.CharField(max_length=255, verbose_name="文章的梗概")
    cover_img_link = models.CharField(max_length=255,verbose_name="文章缩略图的地址",null=True)
    md5_cover_link = models.CharField(max_length=80,verbose_name="文章的缩略图的md5值",null=True)
    spider_from  = models.CharField(max_length=255,verbose_name="爬虫来源",null=True)
    org_name = models.CharField(max_length=255,verbose_name="机构名字",null=False,default="财经早餐")
    article_type = models.CharField(max_length=32,verbose_name="机构的类型",null=False,default="贷款")
    is_pass = models.SmallIntegerField(verbose_name="状态 0草稿 1待审核 2已发布 3驳回(审核不通过)",null=False,default=0,choices=pass_chioces)
    user_for = models.CharField(max_length=32,verbose_name="使用地址",default="51hk")
    spidered = models.BooleanField(verbose_name="是否已经爬完",null=False,default=False)
    class Meta:
        db_table = 'spider_article'
        verbose_name = '文章列表'
        verbose_name_plural = verbose_name

class ArticleContentModel(BaseModel):
    article_content = models.TextField(null=True,verbose_name="文章html内容")    # 文章的内容
    md5_link = models.CharField(max_length=255,verbose_name="文章链接的url的md5值",null=True)    # 文章链接的md5值
    article = models.OneToOneField('ArticleModel')  # 关联文章表 一对一关系
    class Meta:
        db_table='spider_article_content'
        verbose_name = "文章html表"
        verbose_name_plural = verbose_name


class ArticleImgsModel(BaseModel):
    status_choices = (
        (0,"未上传"),
        (1,"已经上传"),
        (2,"未知错误"),
    )
    article = models.ForeignKey("ArticleModel") # 关联文章表 多对一
    img_oss_name = models.CharField(max_length=255,null=False,default='默认图片',verbose_name="oss名字")
    img_oss_url = models.CharField(max_length=255,null=False,default="默认图片",verbose_name="ossurl")
    img_wechat_url = models.CharField(max_length=255,null=False,default="微信默认",verbose_name="图片的原始地址")
    update_state = models.SmallIntegerField(verbose_name="上传状态",choices=status_choices)
    is_covers = models.BooleanField(default=False,verbose_name="是否是封面图片")

    class Meta:
        db_table = 'spider_article_images'
        verbose_name = "文章图片表"
        verbose_name_plural = verbose_name
